import 'package:flutter/material.dart';
import 'package:test_flutter/constant/resources.dart';
import 'package:test_flutter/pages/CardListPage.dart';
import 'package:test_flutter/pages/ConsumptionPage.dart';
import 'package:test_flutter/pages/DryingPage.dart';
import 'package:test_flutter/pages/LaundryPage.dart';
import 'package:test_flutter/pages/RechargePage.dart';
import 'package:test_flutter/utils/common_utils/CustomLocalizations.dart';
import 'package:test_flutter/utils/factory/Fit.dart';

class HistoryPage extends StatefulWidget {
  final Map<String, dynamic> bean;
  HistoryPage(this.bean);
  @override
  HistoryState createState() => new HistoryState();
}

class HistoryState extends State<HistoryPage> with SingleTickerProviderStateMixin{
  TabController _controller;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = TabController(vsync: this, length: _allPages.length);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
          child: Container(
            decoration: BoxDecoration(
                gradient: LinearGradient(colors: [
              Color(0xFF00E579),
              Color(0xFF00E585),
              Color(0xFF00E792),
              Color(0xFF00E8A4),
              Color(0xFF00ECBA)
            ])),
            child:  AppBar(
                centerTitle: true,
                backgroundColor: Colors.transparent,
                title: Container(
                  height: kToolbarHeight,
                  child: TabBar(
                    controller: _controller,
                    indicatorColor: Color(0xFFFFFFFF),
                    isScrollable: true,
                    labelStyle: TextStyle(fontSize: 15.0),
                    indicatorSize: TabBarIndicatorSize.label,
                    tabs: _allPages
                        .map((_Page page) => Tab(
                        text: page.labelId))
                        .toList(),
                  ),
                )),
          ),
          preferredSize: new Size(Fit.scaleX(1080), kToolbarHeight)),
      body: TabBarView(
          controller: _controller,
          children: _allPages.map(buildTabView).toList()),
    );
  }

  Widget buildTabView(_Page page) {
    return Builder(builder: (BuildContext context) {
      switch (page.index) {
        case 0:
          return ConsumptionPage(widget.bean);
          break;
        case 1:
          return RechargePage(widget.bean);
          break;
      }
    });
  }
}


class _Page {
  final String labelId;
  final int index;
  _Page(this.labelId, this.index);
}

final List<_Page> _allPages = <_Page>[
  _Page("消费记录", 0),
  _Page("充值记录", 1),
];
